//
//  VCHttpTool.m
//  VCShop
//
//  Created by VoyageCN on 16/8/19.
//  Copyright © 2016年 VoyageCN. All rights reserved.
//

#import "VCHttpTool.h"

@implementation VCHttpTool

+ (instancetype)sharedManager {
    
    static VCHttpTool *manager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[VCHttpTool alloc] initWithBaseURL:[NSURL URLWithString:@"http://123.57.141.249:8080/beautalk/"]];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    });
    
    return manager;
}

+ (void)GETRequestWithURL:(NSString *)url
          params:(NSDictionary *)params
        success:(requestSuccessBlock)returnSuccess
          error:(requestErrorBlock)returnError {
    
    [[VCHttpTool sharedManager] GET:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (returnSuccess) {
            returnSuccess(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (returnError) {
            returnError(error);
        }
        
    }];
}

+ (void)POSTRequestWithURL:(NSString *)url
           params:(NSDictionary *)params
         success:(requestSuccessBlock)returnSuccess
           error:(requestErrorBlock)returnError {
    
    [[VCHttpTool sharedManager] POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (returnSuccess) {
            returnSuccess(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (returnError) {
            returnError(error);
        }
        
    }];

    
}

@end
